USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-Insert]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	Insert record into table [dbo].[Products_MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@ParentMeasureUnit_ID uniqueidentifier =Null  , 
	@ParentQuantity float =Null  , 
	@Notes varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Products_MeasureUnits](/*[ID], [Product_ID], [MeasureUnit_ID], [ParentMeasureUnit_ID], [ParentQuantity], [Notes]*/)
	VALUES     (/*@ID, @Product_ID, @MeasureUnit_ID, @ParentMeasureUnit_ID, @ParentQuantity, @Notes*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Products_MeasureUnits]
    WHERE  ( [ID] =@ID )
	AND  ( [Product_ID] =@Product_ID )
	AND  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [ParentMeasureUnit_ID] =@ParentMeasureUnit_ID )
	AND  ( [ParentQuantity] =@ParentQuantity )
	AND  ( [Notes] =@Notes )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-update]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	Update record in table [dbo].[Products_MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@ParentMeasureUnit_ID uniqueidentifier =Null  , 
	@ParentQuantity float =Null  , 
	@Notes varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Products_MeasureUnits] SET 
		/*[ID] =@ID, 
		[Product_ID] =@Product_ID, 
		[MeasureUnit_ID] =@MeasureUnit_ID, 
		[ParentMeasureUnit_ID] =@ParentMeasureUnit_ID, 
		[ParentQuantity] =@ParentQuantity, 
		[Notes] =@Notes*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Products_MeasureUnits]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-Insert-Update]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	Insert OR Update record into table [dbo].[Products_MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@Product_ID uniqueidentifier =Null  , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@ParentMeasureUnit_ID uniqueidentifier =Null  , 
	@ParentQuantity float =Null  , 
	@Notes varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Products_MeasureUnits] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Products_MeasureUnits](/*[ID], [Product_ID], [MeasureUnit_ID], [ParentMeasureUnit_ID], [ParentQuantity], [Notes]*/)
		VALUES     (/*@ID, @Product_ID, @MeasureUnit_ID, @ParentMeasureUnit_ID, @ParentQuantity, @Notes*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Products_MeasureUnits] SET 
			/*[ID] =@ID, 
			[Product_ID] =@Product_ID, 
			[MeasureUnit_ID] =@MeasureUnit_ID, 
			[ParentMeasureUnit_ID] =@ParentMeasureUnit_ID, 
			[ParentQuantity] =@ParentQuantity, 
			[Notes] =@Notes*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[Products_MeasureUnits]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-Delete]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	delete records from table [dbo].[Products_MeasureUnits] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@ParentMeasureUnit_ID uniqueidentifier =null  , 
	@ParentQuantity float =null  , 
	@Notes varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Products_MeasureUnits]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [ParentMeasureUnit_ID] = ISNULL(@ParentMeasureUnit_ID, [ParentMeasureUnit_ID]) )
	AND ( [ParentQuantity] = ISNULL(@ParentQuantity, [ParentQuantity]) )
	AND ( [Notes] like ISNULL(@Notes, [Notes]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Products_MeasureUnits-Select]    Script Date: [[20120714223938]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223938]]
-- Description:	select records from table [dbo].[Products_MeasureUnits] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Products_MeasureUnits-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Products_MeasureUnits-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Products_MeasureUnits-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@Product_ID uniqueidentifier =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@ParentMeasureUnit_ID uniqueidentifier =null  , 
	@ParentQuantity float =null  , 
	@Notes varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Products_MeasureUnits]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [Product_ID] = ISNULL(@Product_ID, [Product_ID]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [ParentMeasureUnit_ID] = ISNULL(@ParentMeasureUnit_ID, [ParentMeasureUnit_ID]) )
	AND ( [ParentQuantity] = ISNULL(@ParentQuantity, [ParentQuantity]) )
	AND ( [Notes] like ISNULL(@Notes, [Notes]) )*/
END
GO
-- =============================================
